/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gew.beans;

import gew.services.DimensionValueService;
import gew.table.Table;
import gew.table.TableMeasure;
import gew.system.Constants;
import gew.system.Labels;
import gew.system.RequestParameter;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

@ManagedBean(name = "bnTblTrd")
@RequestScoped
public class TableTradeBean {

    @EJB
    private DataFacade2 dataFacade2;
    
    @EJB
    private DimensionValueService dvs;

    private RequestParameter rp;
    
    Table table;

    @PostConstruct
    public void init() {
        rp = new RequestParameter((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(), dvs);

        table = new Table("fct_trade", rp.getLocaleUrlCode(), 25, 15);
        table.addHorizontalDimension(Constants.HIER_GROUP_REPORTER, "reporter_id", Labels.get_UI_TITLE_REPORTER(rp.getLocale()), rp.getReporterIdsCS(), false, true, "", false, true);
        table.addHorizontalDimension(Constants.HIER_GROUP_COMMODITY, "commodity_id", Labels.get_UI_TITLE_COMMODITY(rp.getLocale()), rp.getCommodityIdsCS(), true, true, "tdd01", true);
        table.addHorizontalDimension(Constants.HIER_GROUP_PARTNER, "partner_id", Labels.get_UI_TITLE_PARTNER(rp.getLocale()), rp.getPartnerIdsCS(), true, true, "", false);
        table.addVerticalDimension(Constants.HIER_GROUP_TRADE_FLOW, "trade_flow_id", Labels.get_UI_TITLE_TRADE_FLOW(rp.getLocale()), rp.getTradeFlowIdsCS(), true, true, "", false, true);
        table.addVerticalDimension(Constants.HIER_GROUP_PERIOD, "period_id", Labels.get_UI_TITLE_PERIOD(rp.getLocale()), rp.getPeriodIdsCS(), true, true, "", false, true);
        table.addMeasure("trade_value", Labels.get_UI_TITLE_TRADE_VALUE(rp.getLocale()), true, true, TableMeasure.OrderBy.DESC);
        table.addMeasure("quantity", Labels.get_UI_TITLE_TRADE_QUANTITY(rp.getLocale()), false, true, TableMeasure.OrderBy.NONE);
        table.addMeasure("netweight", Labels.get_UI_TITLE_TRADE_NETWEIGHT(rp.getLocale()), false, true, TableMeasure.OrderBy.NONE);
        table.loadDimensions(dataFacade2);
        if (rp.isLoadTableData()){
            table.loadData(dataFacade2);
        }
    }

    public Table getTable() {
        return table;
    }
    
    
}
